<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>创建动态分析模式集</title>
<link rel="stylesheet" href="../styles/style.css" type="text/css" />
<link rel="stylesheet" href="../styles/table.css" type="text/css" />
<script src="../script/common.js"></script>
<script type="text/javascript">
$import("rpc.js");
$import("table_list.js");

var status = null;
var completed = false;
var tableList;

/** 1.提交，检查输入 */
function onSubmit()
{
	completed = false;
	status = null;
	
	if ($("trainSetName").value == "" || $("trainSetName").value == null)
	{
		alert("请输入模式集的名称！");
		return;
	}

	if ($("dataset").value == "" || $("dataset").value == null)
	{
		if (confirm("样本文件未选择，确认使用系统默认样本‘bounce.zip’？"))
		{
			createTrainSet();
		}
		return;
	}
	
	var callback = function()
	{
		$("fileForm").submit();
		check();				//检查文件上传进度，完成后开始PE文件分析
	}

	var operation = new Operation("文件.准备上载文件");
	operation.path = "";
	operation.execute(callback);
}

/** 2.检查上载进度 */
function check()
{
	var callback = function (result)
	{
		if (completed) return;

		status = result.status;
		if (status != null)
		{
			if (status.aborted)
			{
				completed = true;
				alert("上载被取消: " + status.reason);
				status = null;
				return;
			}
			if (status.completed)
			{
				completed = true;
				status = null;
				createTrainSet();
				return;
			}
		}
		setTimeout(check, 1000);
	}
	
	var operation = new Operation("文件.获取上载进度");
	operation.execute(callback);
}

/** 3.创建模式集 */
function createTrainSet()
{
	$("progress").style.display = "";			//显示分析的进度条
	
	var callback = function(result)
	{
		showTrainResult(result.trainSetName);
	};
	
	var operation = new Operation("GBID.创建模式集");
	operation.dataset = $("dataset").value;
	operation.trainSetName = $("trainSetName").value;
	operation.execute(callback);
}

/** 4.显示模式集结果 */
function showTrainResult(trainSetName)
{
	$("progress").style.display = "none";
	alert("模式集" + trainSetName + "创建完成，将显示在以下列表中！");
	
	tableList.refresh();
}

/** 模式集展示表格 */
function initTable()
{
	var operations = 
	[
		{icon: "", text: "查看带衍生规则的模式集", onclick: onView1},
		{icon: "", text: "查看不带衍生规则的模式集", onclick: onView2},
		{icon: "", text: "删除", onclick: onDelete}
	];
	var titles = 
	[
		{text:"名称", width:"20%"},
		{text:"创建时间", width:"20%"},
		{text:"操作", width:"40%"}		
	];
	var columns =  
	[
		function(data) { return data.name; },
		function(data) { return data.createTime; },
		function(data) { return TableList.links(operations, data); }
	];   
	var operation = new Operation("GBID.列所有模式集");
	tableList = new TableList(operation, titles, columns);
	tableList.create($("container"));
	tableList.refresh();
}

function onView1()
{
	window.open("../GBIDResult/AllRulesLib.lib", "_blank");
}

function onView2()
{
	window.open("../GBIDResult/NtvRulesLib.lib", "_blank");
}

function onDelete(data)
{
	if (!confirm("确定要删除模式集'" + data.name + "'吗？"))
		return;			
	
	var callback = function()
	{
		alert("模式集'" + data.name + "'删除成功！");
		tableList.refresh();
	}
	var operation = new Operation("GBID.删除模式集");
	operation.trainSetId = data.id;
	operation.execute(callback);
}

function onLoad()
{
	initTable();
}

</script>

</head>
<body onload="onLoad()">
<div id="ur_here"><img src="../images/icon_here.gif" style="align:absmiddle" align="absmiddle"/> 当前位置：首页 » 创建动态分析模式集 </div>
<div id="wrap">
<div id="containaer" >
	<div id="title" class="title">创建模式集</div>
	<div class="filter">
		<div class="filterTitle">
				<table cellpadding=0 cellspacing=0 border=0 width="100%" style="border-right:1px solid #A7B9CF;">
					<tr class='tablecell'>
						<td class='tit' width="20%"><span style="color:red">*</span>模式集名称</td>
						<td class='inp'>
							<input type="text" id="trainSetName" class="form_input_s"/>
						</td>
					</tr>
					<tr class='tablecell'>
						<td class='tit'>选择样本文件</td>
						<td class='inp'>
							<!-- 表单提交，上传文件 -->
							<form id="fileForm" name="fileForm" action = "../upload" method="post" enctype="multipart/form-data" target="upload_result">
								<input id="dataset" name="dataset" type="file" size="40"/>
								<br/>
								<span style="color:red">注：不选择则使用系统默认的样本“bounce.zip”</span>
							</form> 
							<iframe name="upload_result" id="upload_result" style="display:none"></iframe>
						</td>
					</tr>
				</table>
		</div>
		<div class="filterInput" style="padding:15px 0px 0px 25px;">
			<input type="button" class="form_create" onClick="onSubmit()"/>
			<span id="progress" style="display:none">创建中...<img src="../images/loading.gif" align="absmiddle"></span>
		</div>
		<div class="clear"></div>
		<div class="title">已有的模式集</div>
	</div>
	
	<!-- 结果展示div -->
	<div id="container"></div>
	
</div>
</div>
</body>
</html>